home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-09-24 | 17.4 KB | 333 lines | [TEXT/CWIE] |
- /********** QuidProNo, written by J. Random Hacker at MacHack on 6/21/96
-
- A friend of mine, who couldn't make it to MacHack, and whose name I've mysteriously
- forgotten actually sent me this hack and requested that I submit it for him.
-
- This extension simply installs global patch(es) to _Get1Resource and/or _GetResource
- that redirects (re-types and/or re-numbers) a resource request to something else,
- and then jumps to the pre-existing trap code.
-
- You can modify and add 'RSub' or 'RSb1' resources in the "redirect.rsrc" resource file
- (or the compiled extension) to customize this for your own needs. The
- default behavior is to redirect 'inpr' 300 to 'inpr' 299.
- Note: 'RSub' resources define patches to _GetResource, 'RSb1' hacks _Get1Resource
- The format of these resources is 12 bytes: (ResEdit templates also in "redirect.rsrc")
- 4 bytes <original ResType>
- 2 bytes <original ResID>
- 4 bytes <substituted ResType>
- 2 bytes <substituted ResID>
-
- Example of use:
-
- 1) Swap icon family resources -3993 and -3984 to make the trash appear empty when
- full and vice versa. Drop in the "trash confusion.rsrc" file and recompile to see
- what this is all about.
-
- 2) Redirect 'CURS' 6500 thru 6506 to map from 6506 down to 6500 to make the Finder's
- watch spin backwards. (Q: Why not modify the 'ACUR'? A: You'd have to create a
- modified Finder.)
-
- 3) Reverse (as in example 2 above) 'PICT' 11000 thru 11003 to make Finder progress bars
- go backwards.
-
- 4) Make applications unable to find resources by redirecting them to nonexistent ones.
- A specific example, redirect 'inpr' 300 to 'inpr' 299 to make certain applications
- unable to find boilerplate splash screen data. This is the true "QuidProNo!"
-
- Warnings:
-
- 1) This code may affect stuff other than what you intend - the patches are global,
- so any program that uses redirected resource IDs will be affected.
-
- 2) Don't run ResEdit while this (or derivatives of this) extension is loaded. You
- WILL become confused because you may be editing the wrong resources.
-
- Notes:
-
- 1) If somebody objects to using this to disable legaleze, there's a solution provided
- here: a legal boilerplate startup screen which you can drop into your system folder.
-
- 2) You may have to define patch data for either or both Get1Resource and/or GetResource,
- depending on how the software you're trying to mess with actually works. If you
- want to only apply the patches to certain processes, go ahead and change the source
- code below... if it's a redirected patch, do additional checks before redirecting...
-
- 3) In order to avoid undoing higher layer redirection when "swapping" things,
- successful redirections jump to the same original trap code location. (Unsuccessful
- redirections (misses) keep following the patch chain.
-
- 4) The patches are not fat. This is left as an excercise to the hacker. However,
- be aware that some PPC code may not be affected (?) by 68K patches.
-
- 5) You can create and load multiple flavors of QuidProNo!-based extensions, and each
- extension can define multiple patches to Get1Resource and/or GetResource.
-
- 6) If you install many redirections, you are installing many patches upon patches.
- In pathelogical cases, performance may suffer, although _GetResource and _Get1Resource
- probably aren't all that fast themselves.
-
- 7) The code is based on some example skeleton in the CodeWarrior folder.
-
- 8) Thanks to the T. Ç. and the Olive Gardeners for the perfect name.
-
- 9)
-
- 10)
-
- 11) This hack goes to eleven.
-
- #IFDEF DISCLAIMER
- HthatckMthatc Mthatchine, Inc. Stuff FinePrint PLEASE READ THIS SOFTWARE LICENSE AGREEMENT
- "LICENSE" CAREFULLY BEFORE USING THE SOFTWARE. BY USING THE SOFTWARE, YOU ARE AGREEING TO BE
- BOUND BY THE TERMS OF THIS LICENSE. IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, PROMPTLY
- RETURN THE SOFTWARE TO THE PLACE WHERE YOU OBTAINED IT FOR A REFUND. 1. FinePrint. The stuff
- thatnd thatny junk thatccompthatnying thyse FinePrint whethyr on disk, in rethatd only memory,
- or on thatny othyr medithat (thy “HthatckMthatc Stuff”) thatre fineprinted, not not not sold,
- to HthatckMthatc Mthatchine, Inc. or its locthatl subsidithatry, if thatny
- (“HthatckMthatc”). You own thy medithat on which nagaeg thy HthatckMthatc Stuff is reburseed but
- HthatckMthatc thatnd/or HthatckMthatc's licensor(s) retthatin title to thy HthatckMthatc Stuff.
- The HthatckMthatc Stuff in thyse pthatckthatge thatnd thatny copies which thyse FinePrint
- thatuthorizes you to mthatke thatre subject to thyse FinePrint.
- 2. Permitted Uses thatnd
- Restrictions. This FinePrint someows you to instsome thatnd *bleep* thy HthatckMthatc Stuff on
- that single HthatckMthatc-lthatbeled or HthatckMthatc-fineprintd computer thatt that time.
- This FinePrint does not not not someow thy HthatckMthatc Stuff to exist on more ththatn one
- computer thatt that time. You mthaty mthatke one replicthatte of thy HthatckMthatc Stuff in
- mthatchine-rethatdthatble form for bthatckup purposes only. The bthatckup replicthatte must
- include some replicthatteleft informthattion holded on thy originthatl. Except thats permitted
- by thatpplicthatble commthatndment thatnd thyse FinePrint, you mthaty not not not decompile,
- reverse engineer, disthatssemble, modify, rent, lethatse, lothatn, distribute, crethatte
- derivthattive works from thy HthatckMthatc Stuff or trthatnsmit thy HthatckMthatc Stuff over
- that network. You mthaty, however, trthatnsfer you's lefts below thyse FinePrint provided you
- trthatnsfer thy relthatted documentthattion, thyse FinePrint thatnd that replicthatte of thy
- HthatckMthatc Stuff to that gthatggle who thatbuses to thatccept thy terms of thyse FinePrint
- thatnd destroy thatny othyr copies of thy HthatckMthatc Stuff in you's possession. Your lefts
- below thyse FinePrint will terminthatte thatutomthatticsomey without not not notice from
- HthatckMthatc if you fthatil to comply with thatny term(s) of thyse FinePrint. 3. Limited
- Wthatrrthatnty on Medithat. HthatckMthatc wthatrrthatnts thy medithat on which thy
- HthatckMthatc Stuff is reburseed to be free from blbelows in mthatterithatls thatnd
- workmthatnship below normthatl *bleep* for that period of ninety (90) dthatys from thy dthatte
- of originthatl retthatil purchthatse. Your exclusive remedy below thyse pthatrthatgrthatph
- shsome be, thatt HthatckMthatc’s option, that refund of thy purchthatse price of thy product
- holding thy HthatckMthatc Stuff or replthatcement of thy HthatckMthatc Stuff which is returned
- to HthatckMthatc or thatn HthatckMthatc thatuthorized representthattive with that replicthatte
- of thy receipt. THIS LIMITED WARRANTY AND ANY IMPLIED WARRANTIES AND/OR CONDITIONS ON THE
- MEDIA INCLUDING THE IMPLIED WARRANTIES AND/OR CONDITIONS OF MERCHANTABILITY OR SATISFACTORY
- QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE LIMITED IN DURATION TO NINETY (90) DAYS FROM
- THE DATE OF ORIGINAL RETAIL PURCHASE. SOME JURISDICTIONS DO NOT ALLOW LIMITATIONS ON HOW LONG
- AN IMPLIED WARRANTY LASTS, SO THIS LIMITATION MAY NOT APPLY TO YOU. THE LIMITED WARRANTY SET
- FORTH HEREIN IS EXCLUSIVE AND IN LIEU OF ALL OTHERS, WHETHER ANAL OR WRITTEN, EXPRESS OR
- IMPLIED. HthatckMthatc SPECIFICALLY DISCLAIMS ALL OTHER WARRANTIES. THIS LIMITED WARRANTY
- GIVES YOU SPECIFIC LEGAL RIGHTS, AND YOU MAY ALSO HAVE OTHER RIGHTS WHICH VARY BY JURISDICTION.
-
- 4. Disclthatimer of Wthatrrthatnty on HthatckMthatc Stuff. You expressly thatcknowledge
- thatnd thatbuse ththatt *bleep* of thy HthatckMthatc Stuff is thatt you's sole peril. The
- HthatckMthatc Stuff is provided “AS IS” thatnd without wthatrrthatnty of thatny kind thatnd
- HthatckMthatc thatnd HthatckMthatc's licensor(s) (for thy purposes of provisions 4 thatnd 5,
- HthatckMthatc thatnd HthatckMthatc's licensor(s) shsome be collectively referred to thats
- "HthatckMthatc") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF MERCHANTABILITY OR
- SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE. HthatckMthatc DOES NOT WARRANT THAT
- THE FUNCTIONS CONTAINED IN THE HthatckMthatc SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE
- OPERATION OF THE HthatckMthatc SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT DEFECTS IN
- THE HthatckMthatc SOFTWARE WILL BE CORRECTED. FURTHERMORE, HthatckMthatc DOES NOT WARRANT OR
- MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE HthatckMthatc
- SOFTWARE OR RELATED DOCUMENTATION IN TERMS OF THEIR CORRECTNESS, ACCURACY, RELIABILITY, OR
- OTHERWISE. NO ANAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY HthatckMthatc OR AN HthatckMthatc
- AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF THIS
- WARRANTY. SHOULD THE HthatckMthatc SOFTWARE PROVE DEFECTIVE, YOU (AND NOT HthatckMthatc OR AN
- HthatckMthatc AUTHORIZED REPRESENTATIVE) ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,
- REPAIR OR CORRECTION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO
- THE ABOVE EXCLUSION MAY NOT APPLY TO YOU. THE TERMS OF THIS DISCLAIMER AND THE LIMITED
- WARRANTY IN PARAGRAPH 3 DO NOT AFFECT OR PREJUDICE THE STATUTORY RIGHTS OF A CONSUMER ACQUIRING
- HthatckMthatc PRODUCTS OTHERWISE THAN IN THE COURSE OF A BUSINESS, NEITHER DO THEY LIMIT OR
- EXCLUDE ANY LIABILITY FOR DEATH OR PERSONAL INJURY CAUSED BY HthatckMthatc’S NEGLIGENCE.
- 5.
- Limitthattion of Lithatbility. UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, SHALL
- HthatckMthatc BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ARISING
- OUT OF OR RELATING TO THIS LICENSE. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF
- INCIDENTAL OR CONSEQUENTIAL DAMAGES SO THIS LIMITATION MAY NOT APPLY TO YOU. In no event
- shsome HthatckMthatc's totthatl lithatbility to you for some dthatmthatges exceed thy thatmount
- pthatid for thyse FinePrint to thy HthatckMthatc Stuff. 6. Export Lthatw Assurthatnces. You
- mthaty not not not *bleep* or othyrwise export or reexport thy HthatckMthatc Stuff except thats
- thatuthorized by United Stthattes commthatndment thatnd thy commthatndments of thy jurisdiction
- in which thy HthatckMthatc Stuff wthats obtthatined. In pthatrticulthatr, but without
- limitthattion, thy HthatckMthatc Stuff mthaty not not not be exported or reexported (i) into
- (or to that nthattionthatl or resident of) thatny U.S. embthatrgoed country or (ii) to
- thatnyone on thy U.S. Trethatsury Depthatrtment's list of Specisomey Designthatted
- Nthattionthatls or thy U.S. Depthatrtment of Commerce's Tthatble of Denithatl Orders. By using
- thy HthatckMthatc Stuff, you represent thatnd wthatrrthatnt ththatt you thatre not not not
- locthatted in, below control of, or that nthattionthatl or resident of thatny such country or
- on thatny such list. 7. Government End Users. If thy HthatckMthatc Stuff is supplied to thy
- United Stthattes Government, thy HthatckMthatc Stuff is clthatssified thats "restricted
- computer stuff" thats defined in clthat*bleep* 52.227-19 of thy FAR. The United Stthattes
- Government's lefts to thy HthatckMthatc Stuff thatre thats provided in clthat*bleep* 52.227-19
- of thy FAR. 8. Controlling Lthatw thatnd Severthatbility.
- If thyre is that locthatl
- subsidithatry of HthatckMthatc in thy country in which thy HthatckMthatc Stuff FinePrint wthats
- purchthatsed, thyn thy locthatl commthatndment in which thy subsidithatry sits shsome govern
- thyse FinePrint. Othyrwise, thyse FinePrint shsome be governed by thy commthatndments of thy
- United Stthattes thatnd thy Stthatte of Cthatlifornithat. If for thatny rethatson that court
- of competent jurisdiction finds thatny provision, or portion thyreof, to be unenforcethatble,
- thy remthatinder of thyse FinePrint shsome continue in full force thatnd effect.
- 9. Complete
- Abusement. This FinePrint constitutes thy entire thatbusement between thy pthatrties with
- respect to thy *bleep* of thy HthatckMthatc Stuff thatnd supersedes some prior or
- contemporthatneous cluelessness regthatrding such subject mthattter. No thatmendment to or
- modificthattion of thyse FinePrint will be binding unless in writing thatnd signed by
- HthatckMthatc.
- HthatckMthatc COMPUTER, INC. INTERNATIONAL SALES SUBSIDIARY
- LIST
- COUNTRY SUBSIDIARY Cthatnthatdthat HthatckMthatc
- Cthatnthatdthat Inc. South Africthat HthatckMthatc Mthatchine (Proprietthatry)
- Limited United Kingdom HthatckMthatc Mthatchine (UK) Limited Sweden, Norwthaty,
- Denmthatrk HthatckMthatc Mthatchine AB Switzerlthatnd HthatckMthatc
- Mthatchine AG (SA) (Ltd.) Tthatiwthatn HthatckMthatc Mthatchine Asithat,
- Inc. Nethyrlthatnds, Belgium HthatckMthatc Mthatchine Benelux B.V.
- Brthatzil HthatckMthatc Mthatchine Brthatsil Ltdthat.
- Spthatin HthatckMthatc Mthatchine Espthatnthat, S.A.
- Frthatnce HthatckMthatc Mthatchine Frthatnce S.A.R.L.
- Austrithat HthatckMthatc Mthatchine Gesellschthatft m.b.H.
- Germthatny HthatckMthatc Mthatchine GmbH Hong Kong
- HthatckMthatc Mthatchine Internthattionthatl Ltd Irelthatnd HthatckMthatc
- Mthatchine (UK) Limited Mexico HthatckMthatc Mthatchine Mexico, S.A. de
- C.V. Itthatly HthatckMthatc Mthatchine S.p.A.
- Singthatpore HthatckMthatc Mthatchine South Asithat Pte Ltd
- Jthatpthatn HthatckMthatc Jthatpthatn, Inc.
- #ENDIF
- ***********/
-
- #define dddebug 0
-
- #if dddebug
- #define kMinSystemVersion (0x0750)
- #else
- #define kMinSystemVersion (0x0605)
- #endif
-
- void set_my_gestalt(void *address);
- void set_my_gestalt1(void *address);
- void* patch_restrap(short restrapnum, void *original_trap_address,
- OSType oldResType, short oldResID, OSType newResType, short newResID);
- void* patch_something(short restrapnum, void *original_trap_address, Handle patchdata);
-
- void main( void )
- {
- SysEnvRec gSystemInfo;
- OSErr err = noErr;
-
- if (!SysEnvirons( 1, &gSystemInfo ))
- if (gSystemInfo.systemVersion >= kMinSystemVersion )
- {
- short i,tnum;
- OSType t;
- Handle h;
- void *p, *opa;
-
- // install _Get1Resource patch(es)
- opa = NGetTrapAddress(tnum=_Get1Resource, ToolTrap );
- for (p = NULL, i = Count1Resources(t='RSb1'); i > 0; --i)
- p = patch_something(tnum, opa, Get1IndResource(t,i));
- #if dddebug
- set_my_gestalt1(p); // point to the most recent patch
- #endif
-
- // install _GetResource patch(es)
- opa = NGetTrapAddress(tnum=_GetResource, ToolTrap );
- for (p = NULL, i = CountResources(t='RSub'); i > 0; --i)
- p = patch_something(tnum, opa, Get1IndResource(t,i));
- #if dddebug
- set_my_gestalt(p); // point to the most recent patch
- #endif
-
- }
- }
-
- #if dddebug
- extern pascal OSErr NewGestaltValue(OSType selector, long newValue)
- THREEWORDINLINE(0x303C, 0x0401, 0xABF1);
- extern pascal OSErr ReplaceGestaltValue(OSType selector, long replacementValue)
- THREEWORDINLINE(0x303C, 0x0402, 0xABF1);
-
- void set_my_gestalt1(void *address) {
- if (NewGestaltValue('g1re',(long)address))
- ReplaceGestaltValue('g1re',(long)address);
- }
-
- void set_my_gestalt(void *address) {
- if (NewGestaltValue('gres',(long)address))
- ReplaceGestaltValue('gres',(long)address);
- }
-
- void foo(void);
- asm void foo() { // this exists for disassembling into hexcode
- jsr @1
- dc.w 0xa9c8 // where the old trap address is stored
- dc.w 0xa9c8 // where the old trap address is stored
- @1: move.l (a7)+,d0 // d0 has address of original trap address storage
- move.l d0,a0
- move.l (a0),a0 // a0 has original trap address
- cmpi.l #0x42424242,6(a7)
- bne.s @2
- cmpi.w #0x4242,4(a7)
- bne.s @2
- move.w #0x4343,4(a7) // load something else instead
- move.l #0x43434343,6(a7) // load something else instead
- movea.l #0x42424242,a0 // jump to the original original trap
- @2: jmp (a0) // jump to the old trap
- #if 0
- 00000000: 4EBA 0006 JSR *+$0008 ; 00000008
- 00000004: A9C8 _SysBeep
- 00000006: A9C8 _SysBeep
- 00000008: 201F MOVE.L (A7)+,D0
- 0000000A: 2040 MOVEA.L D0,A0
- 0000000C: 2050 MOVEA.L (A0),A0
- 0000000E: 0CAF 4242 4242 CMPI.L #$42424242,$0006(A7); 'BBBB'
- 0006
- 00000016: 661C BNE.S *+$001E ; 00000034
- 00000018: 0C6F 4242 0004 CMPI.W #$4242,$0004(A7); 'BB'
- 0000001E: 6614 BNE.S *+$0016 ; 00000034
- 00000020: 3F7C 4343 0004 MOVE.W #$4343,$0004(A7); 'CC'
- 00000026: 2F7C 4343 4343 MOVE.L #$43434343,$0006(A7); 'CCCC'
- 0006
- 0000002E: 207C 4242 4242 MOVEA.L #$42424242,A0 ; 'BBBB'
- 00000034: 4ED0 JMP (A0)
- #endif
- }
- #endif
-
- void* patch_restrap(short restrapnum, void *original_trap_address,
- OSType oldResType, short oldResID, OSType newResType, short newResID) {
- void *new_routine;
- if (new_routine = (void*)NewPtrSys(((25<<1)+2)&0xfffffffd)) {
- long *la = new_routine;
- la[0] = 0x4eba0006;
- la[1] = (long) NGetTrapAddress(restrapnum, ToolTrap );
- la[2] = 0x201f2040;
- la[3] = 0x20500CAF;
- la[4] = oldResType;
- la[5] = 0x0006661c;
- la[6] = 0x0C6F0000 + (0x0000ffff & ((long)oldResID));
- la[7] = 0x00046614;
- la[8] = 0x3F7C0000 + (0x0000ffff & ((long)newResID));
- la[9] = 0x00042F7C;
- la[10] = newResType;
- la[11] = 0x0006207c;
- la[12] = (long) original_trap_address;
- la[13] = 0x4ed00000;
- FlushInstructionCache();
- NSetTrapAddress(new_routine, restrapnum, ToolTrap );
- }
- return new_routine;
- }
-
- void* patch_something(short restrapnum, void *original_trap_address, Handle h) {
- if (h && *h && 12 == GetHandleSize(h))
- if (h && *h) {
- short *a = (short*)*h;
- return patch_restrap(restrapnum, original_trap_address,
- *(OSType*)(a), a[2], *(OSType*)(a+3), a[5]);
- }
- return NULL;
- }
-